class DashboardController < ApplicationController
  
  def index
    @user = User.find(:first)
    @gadgets = @user.gadgets
    @gadget_json = @gadgets.to_json
    @all_gadgets = Gadget.find_all_by_published(true)
    @categories = Category.find(:all)
  end
  
  
  def p
    @gadgets = Gadget.find_all_by_installed(true)
    @gadget_json = @gadgets.to_json
  end
  
  
  # Adds/Installs a Gadget to the Dashboard
  def add_gadget
    @user = User.find(:first)
    @gadget = Gadget.find(params[:id])
    @user.gadgets << @gadget
    @gadgets = @user.gadgets
    @gadget_json = @gadgets.to_json
    render :text=>@gadget_json, :layout=>false
  end
  
  
  # Removes/Uninstalls a Gadget from the Dashboard
  def remove_gadget
    @user = User.find(:first)
    @gadget = Gadget.find_by_container_id(params[:chrome_id])
    #@gadget.update_attribute('installed', false);
    @user.gadgets.delete @gadget
    @gadgets = @user.gadgets
    @gadget_json = @gadgets.to_json
    render :text=>@gadget_json, :layout=>false
  end
  
end
